-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
containerapps-albumapi-go
test project & cases (#707)
- Loading branch information
1 parent
a1210d4
commit 48c92ef
Showing
14 changed files
with
376 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
test/nightly/deployWorkspaceProject/testCases/albumApiGolangTestCases.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See LICENSE.md in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
import { randomUtils } from "@microsoft/vscode-azext-utils"; | ||
import * as path from "path"; | ||
import { type DeploymentConfigurationSettings } from "../../../../extension.bundle"; | ||
import { type StringOrRegExpProps } from "../../../typeUtils"; | ||
import { dwpTestUtils } from "../dwpTestUtils"; | ||
import { type DeployWorkspaceProjectTestCase } from "./DeployWorkspaceProjectTestCase"; | ||
|
||
export function generateAlbumApiGolangTestCases(): DeployWorkspaceProjectTestCase[] { | ||
const folderName: string = 'albumapi-go'; | ||
const appResourceName: string = 'album-api'; | ||
const sharedResourceName: string = appResourceName + randomUtils.getRandomHexString(4); | ||
const acrResourceName: string = sharedResourceName.replace(/[^a-zA-Z0-9]+/g, ''); | ||
|
||
return [ | ||
{ | ||
label: 'Deploy App', | ||
inputs: [ | ||
new RegExp(folderName, 'i'), | ||
new RegExp('Create new container apps environment', 'i'), | ||
'Continue', | ||
sharedResourceName, | ||
appResourceName, | ||
`.${path.sep}src`, | ||
'East US', | ||
'Save' | ||
], | ||
expectedResults: dwpTestUtils.generateExpectedResults(sharedResourceName, acrResourceName, appResourceName), | ||
expectedVSCodeSettings: { | ||
deploymentConfigurations: [ | ||
generateExpectedDeploymentConfiguration(sharedResourceName, acrResourceName, appResourceName) | ||
] | ||
}, | ||
postTestAssertion: dwpTestUtils.generatePostTestAssertion({ targetPort: 8080, env: undefined }) | ||
}, | ||
{ | ||
label: 'Re-deploy App', | ||
inputs: [ | ||
new RegExp(folderName, 'i'), | ||
appResourceName, | ||
'Continue' | ||
], | ||
expectedResults: dwpTestUtils.generateExpectedResults(sharedResourceName, acrResourceName, appResourceName), | ||
expectedVSCodeSettings: { | ||
deploymentConfigurations: [ | ||
generateExpectedDeploymentConfiguration(sharedResourceName, acrResourceName, appResourceName) | ||
] | ||
}, | ||
postTestAssertion: dwpTestUtils.generatePostTestAssertion({ targetPort: 8080, env: undefined }) | ||
} | ||
]; | ||
} | ||
|
||
function generateExpectedDeploymentConfiguration(sharedResourceName: string, acrResourceName: string, appResourceName: string): StringOrRegExpProps<DeploymentConfigurationSettings> { | ||
return { | ||
label: appResourceName, | ||
type: 'AcrDockerBuildRequest', | ||
dockerfilePath: path.join('src', 'Dockerfile'), | ||
srcPath: 'src', | ||
envPath: '', | ||
resourceGroup: sharedResourceName, | ||
containerApp: appResourceName, | ||
containerRegistry: new RegExp(`${acrResourceName}.{6}`, 'i'), | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) Microsoft Corporation. | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Azure Container Apps Album API | ||
|
||
Originally adapted from [this](https://github.com/azure-samples/containerapps-albumapi-go) repository, the companion repository for the [Azure Container Apps code-to-cloud quickstart](https://learn.microsoft.com/en-us/azure/container-apps/quickstart-code-to-cloud?tabs=bash%2Cgo&pivots=with-dockerfile). |
24 changes: 24 additions & 0 deletions
24
test/testProjects/containerapps-albumapi-go/src/.dockerignore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
**/.classpath | ||
**/.dockerignore | ||
**/.env | ||
**/.git | ||
**/.gitignore | ||
**/.project | ||
**/.settings | ||
**/.toolstarget | ||
**/.vs | ||
**/.vscode | ||
**/*.*proj.user | ||
**/*.dbmdl | ||
**/*.jfm | ||
**/bin | ||
**/charts | ||
**/docker-compose* | ||
**/compose* | ||
**/Dockerfile* | ||
**/node_modules | ||
**/npm-debug.log | ||
**/obj | ||
**/secrets.dev.yaml | ||
**/values.dev.yaml | ||
README.md |
19 changes: 19 additions & 0 deletions
19
test/testProjects/containerapps-albumapi-go/src/Dockerfile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Dockerfile References: https://docs.docker.com/engine/reference/builder/ | ||
|
||
# Start from the latest golang base image | ||
FROM golang:latest | ||
|
||
# Set the Current Working Directory inside the container | ||
WORKDIR /app | ||
|
||
# Add files to app folder | ||
ADD . /app | ||
|
||
# Build the Go app | ||
RUN go build -o main . | ||
|
||
# Expose ports to the outside world | ||
EXPOSE 8080 | ||
|
||
# Command to run the executable | ||
CMD ["./main"] |
23 changes: 23 additions & 0 deletions
23
test/testProjects/containerapps-albumapi-go/src/controllers/album/album.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package album | ||
|
||
import ( | ||
"album-service/models" | ||
"encoding/json" | ||
"fmt" | ||
"net/http" | ||
) | ||
|
||
func init() { | ||
fmt.Println("Initialize - album package") | ||
} | ||
|
||
// Get function | ||
func Get(w http.ResponseWriter, r *http.Request) { | ||
|
||
// serialize data | ||
j, _ := json.Marshal(models.GetAlbums()) | ||
|
||
// set response | ||
w.Header().Set("Content-Type", "application/json") | ||
w.Write(j) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
module album-service | ||
|
||
go 1.17 | ||
|
||
require ( | ||
github.com/gorilla/mux v1.8.0 | ||
github.com/rs/cors v1.8.2 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI= | ||
github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So= | ||
github.com/rs/cors v1.8.2 h1:KCooALfAYGs415Cwu5ABvv9n9509fSiG5SQJn/AQo4U= | ||
github.com/rs/cors v1.8.2/go.mod h1:XyqrcTp5zjWr1wsJ8PIRZssZ8b/WMcMf71DJnit4EMU= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package main | ||
|
||
import ( | ||
"album-service/controllers/album" | ||
"fmt" | ||
"log" | ||
"net/http" | ||
"os" | ||
"strings" | ||
|
||
"github.com/gorilla/mux" | ||
"github.com/rs/cors" | ||
) | ||
|
||
func main() { | ||
|
||
// router implementation | ||
router := mux.NewRouter() | ||
|
||
// adding cors | ||
c := cors.AllowAll() | ||
handler := c.Handler(router) | ||
|
||
port, ok := os.LookupEnv("PORT") | ||
if !ok { | ||
port = "8080" | ||
} | ||
|
||
router.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { | ||
w.WriteHeader(http.StatusOK) | ||
fmt.Fprintf(w, "Access /albums to see the list of albums") | ||
}) | ||
|
||
router.HandleFunc("/albums", album.Get).Methods("GET") | ||
|
||
// listen and serve | ||
log.Printf("will listen on %v\n", port) | ||
if err := http.ListenAndServe(":" + port, trailingSlashHandler(handler)); err != nil { | ||
log.Fatalf("unable to start http server, %s", err) | ||
} | ||
} | ||
|
||
func trailingSlashHandler(next http.Handler) http.Handler { | ||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
if r.URL.Path != "/" { | ||
r.URL.Path = strings.TrimSuffix(r.URL.Path, "/") | ||
} | ||
next.ServeHTTP(w, r) | ||
}) | ||
} |
Oops, something went wrong.