- 
                Notifications
    
You must be signed in to change notification settings  - Fork 61
 
add docker compose extension support #679
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
          
     Merged
      
      
    
  
     Merged
                    Changes from all commits
      Commits
    
    
  File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or 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,70 @@ | ||
| /* | ||
| Copyright 2025 API Testing Authors. | ||
| 
     | 
||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
| 
     | 
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
| 
     | 
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| */ | ||
| 
     | 
||
| package cmd | ||
| 
     | 
||
| import ( | ||
| "fmt" | ||
| "strings" | ||
| 
     | 
||
| "github.com/spf13/cobra" | ||
| ) | ||
| 
     | 
||
| type composeOptions struct { | ||
| runOption | ||
| projectName string | ||
| } | ||
| 
     | 
||
| func createComposeRun() *cobra.Command { | ||
| cmd := &cobra.Command{ | ||
| Use: "compose", | ||
| } | ||
| 
     | 
||
| cmd.AddCommand(createComposeRunUp()) | ||
| return cmd | ||
| } | ||
| 
     | 
||
| type composeMsgWriter struct { | ||
| } | ||
| 
     | 
||
| func (w *composeMsgWriter) Write(p []byte) (n int, err error) { | ||
| fmt.Println(`{ "type": "info", "message": "` + strings.TrimSpace(string(p)) + `" }`) | ||
| return | ||
| } | ||
| 
     | 
||
| func (o *composeOptions) preRunE(cmd *cobra.Command, args []string) error { | ||
| return o.runOption.preRunE(cmd, nil) | ||
| } | ||
| 
     | 
||
| func (o *composeOptions) runE(cmd *cobra.Command, args []string) error { | ||
| return o.runOption.runE(cmd, args) | ||
| } | ||
| 
     | 
||
| func createComposeRunUp() *cobra.Command { | ||
| opt := &composeOptions{ | ||
| runOption: *newDefaultRunOption(&composeMsgWriter{}), | ||
| } | ||
| c := &cobra.Command{ | ||
| Use: "up", | ||
| PreRunE: opt.preRunE, | ||
| RunE: opt.runE, | ||
| } | ||
| c.SetOut(&composeMsgWriter{}) | ||
| 
     | 
||
| c.Flags().StringVarP(&opt.projectName, "project-name", "", "", "Specify an alternate project name") | ||
| opt.runOption.addFlags(c.Flags()) | ||
| return c | ||
| } | 
  
    
      This file contains hidden or 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 hidden or 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 hidden or 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 | 
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| +++ | ||
| title = "代码生成" | ||
| weight = 103 | ||
| weight = 104 | ||
| +++ | ||
| 
     | 
||
| `atest` 支持把测试用例生成多种开发语言的代码: | ||
| 
          
            
          
           | 
    ||
  
    
      This file contains hidden or 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,58 @@ | ||
| +++ | ||
| title = "End-to-End" | ||
| weight = 103 | ||
| +++ | ||
| 
     | 
||
| `atest` 非常适合针对(HTTP)接口做 E2E(端到端)测试,E2E 测试可以确保后端接口在完整的环境中持续地保持正确运行。下面采用 Docker compose 给出一个使用事例: | ||
| 
     | 
||
| ```yaml | ||
| version: '3.1' | ||
| services: | ||
| testing: | ||
| image: ghcr.io/linuxsuren/api-testing:latest | ||
| environment: | ||
| SERVER: http://server:8080 | ||
| volumes: | ||
| - ./testsuite.yaml:/work/testsuite.yaml | ||
| command: atest run -p /work/testsuite.yaml | ||
| depends_on: | ||
| server: | ||
| condition: service_healthy | ||
| links: | ||
| - server | ||
| server: | ||
| image: ghcr.io/devops-ws/learn-springboot:master | ||
| healthcheck: | ||
| test: ["CMD", "bash", "-c", "cat < /dev/null > /dev/tcp/127.0.0.1/8080"] | ||
| interval: 3s | ||
| timeout: 60s | ||
| retries: 10 | ||
| start_period: 3s | ||
| ``` | ||
| 
     | 
||
| 从 Docker compose `v2.36.0` 开始,可以采用如下简化的写法: | ||
| 
     | 
||
| ```yaml | ||
| services: | ||
| testing: | ||
| scale: 0 | ||
| provider: | ||
| type: atest | ||
| options: | ||
| pattern: testsuite.yaml | ||
| environment: | ||
| SERVER: http://server:8080 | ||
| depends_on: | ||
| server: | ||
| condition: service_healthy | ||
| links: | ||
| - server | ||
| server: | ||
| image: ghcr.io/devops-ws/learn-springboot:master | ||
| healthcheck: | ||
| test: ["CMD", "bash", "-c", "cat < /dev/null > /dev/tcp/127.0.0.1/8080"] | ||
| interval: 3s | ||
| timeout: 60s | ||
| retries: 10 | ||
| start_period: 3s | ||
| ``` | 
  
    
      This file contains hidden or 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,9 @@ | ||
| #!api-testing | ||
| # yaml-language-server: $schema=https://linuxsuren.github.io/api-testing/api-testing-schema.json | ||
| name: SpringBoot | ||
| api: | | ||
| {{default "http://localhost:8080" (env "SERVER")}} | ||
| items: | ||
| - name: health | ||
| request: | ||
| api: /health | 
  
    
      This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
    
  
  
    
              
      
      Oops, something went wrong.
        
    
  
      
      Oops, something went wrong.
        
    
  
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
Uh oh!
There was an error while loading. Please reload this page.