• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

astronomer / astro-cli / 23d6d326-ef83-487f-9901-f16bd900b13d

25 Nov 2025 12:02PM UTC coverage: 33.132% (-5.5%) from 38.64%
23d6d326-ef83-487f-9901-f16bd900b13d

push

circleci

web-flow
feat: add runtime version validation for remote client deployments (#1983)

76 of 80 new or added lines in 4 files covered. (95.0%)

3547 existing lines in 30 files now uncovered.

20844 of 62912 relevant lines covered (33.13%)

8.49 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/pkg/testing/testing.go
1
package testing
2

3
import (
4
        "fmt"
5
        "net/http"
6
        "os"
7
        "strings"
8
        "testing"
9

10
        "github.com/astronomer/astro-cli/config"
11
        "github.com/astronomer/astro-cli/pkg/httputil"
12
        "github.com/spf13/afero"
13
        "github.com/stretchr/testify/require"
14
)
15

16
const (
17
        LocalPlatform         = "local"
18
        CloudPlatform         = "cloud"
19
        CloudDevPlatform      = "dev"
20
        CloudPerfPlatform     = "perf"
21
        CloudStagePlatform    = "stage"
22
        CloudPrPreview        = "prpreview"
23
        SoftwarePlatform      = "software"
24
        Initial               = "initial"
25
        ErrorReturningContext = "error"
26
)
27

28
var perm os.FileMode = 0o777
29

30
// RoundTripFunc
31
type RoundTripFunc func(req *http.Request) *http.Response
32

33
// RoundTrip
UNCOV
34
func (f RoundTripFunc) RoundTrip(req *http.Request) (*http.Response, error) {
×
UNCOV
35
        return f(req), nil
×
UNCOV
36
}
×
37

38
// NewTestClient returns *httputil.HTTPClient with Transport replaced to avoid making real calls
UNCOV
39
func NewTestClient(fn RoundTripFunc) *httputil.HTTPClient {
×
UNCOV
40
        testClient := httputil.NewHTTPClient()
×
UNCOV
41
        testClient.HTTPClient.Transport = fn
×
UNCOV
42
        return testClient
×
UNCOV
43
}
×
44

UNCOV
45
func GetEnv(key, fallback string) string {
×
UNCOV
46
        if value, ok := os.LookupEnv(key); ok {
×
47
                return value
×
48
        }
×
UNCOV
49
        return fallback
×
50
}
51

UNCOV
52
func NewTestConfig(platform string) []byte {
×
UNCOV
53
        testConfig := `cloud:
×
UNCOV
54
  api:
×
UNCOV
55
    port: "443"
×
UNCOV
56
    protocol: https
×
UNCOV
57
    ws_protocol: wss
×
UNCOV
58
local:
×
UNCOV
59
  enabled: true
×
UNCOV
60
  host: http://localhost:8871/v1
×
UNCOV
61
duplicate_volumes: true
×
UNCOV
62
context: %s
×
UNCOV
63
contexts:
×
UNCOV
64
  %s:
×
UNCOV
65
    domain: %s
×
UNCOV
66
    token: token
×
UNCOV
67
    last_used_workspace: ck05r3bor07h40d02y2hw4n4v
×
UNCOV
68
    workspace: ck05r3bor07h40d02y2hw4n4v
×
UNCOV
69
    organization: test-org-id
×
UNCOV
70
    organization_short_name: test-org-short-name
×
UNCOV
71
disable_env_objects: false
×
UNCOV
72
`
×
UNCOV
73
        switch platform {
×
UNCOV
74
        case CloudPlatform:
×
UNCOV
75
                testConfig = fmt.Sprintf(testConfig, "astronomer.io", strings.Replace("astronomer.io", ".", "_", -1), "astronomer.io")
×
UNCOV
76
        case CloudDevPlatform:
×
UNCOV
77
                testConfig = fmt.Sprintf(testConfig, "astronomer-dev.io", strings.Replace("astronomer-dev.io", ".", "_", -1), "astronomer-dev.io")
×
UNCOV
78
        case CloudStagePlatform:
×
UNCOV
79
                testConfig = fmt.Sprintf(testConfig, "astronomer-stage.io", strings.Replace("astronomer-stage.io", ".", "_", -1), "astronomer-stage.io")
×
UNCOV
80
        case CloudPerfPlatform:
×
UNCOV
81
                testConfig = fmt.Sprintf(testConfig, "astronomer-perf.io", strings.Replace("astronomer-perf.io", ".", "_", -1), "astronomer-perf.io")
×
UNCOV
82
        case SoftwarePlatform:
×
UNCOV
83
                testConfig = fmt.Sprintf(testConfig, "astronomer_dev.com", strings.Replace("astronomer_dev.com", ".", "_", -1), "astronomer_dev.com")
×
UNCOV
84
        case LocalPlatform:
×
UNCOV
85
                testConfig = fmt.Sprintf(testConfig, "localhost", "localhost", "localhost")
×
UNCOV
86
        case Initial:
×
UNCOV
87
                testConfig = ""
×
88

UNCOV
89
        case CloudPrPreview:
×
UNCOV
90
                testConfig = fmt.Sprintf(testConfig, "pr1234.astronomer-dev.io", strings.Replace("pr1234.astronomer-dev.io", ".", "_", -1), "pr1234.astronomer-dev.io")
×
UNCOV
91
        case ErrorReturningContext:
×
UNCOV
92
                // this is an error returning case
×
UNCOV
93
                testConfig = fmt.Sprintf(testConfig, "error", "error", "error")
×
UNCOV
94
                testConfig = strings.Replace(testConfig, "context: error", "context: ", 1)
×
UNCOV
95
        default:
×
UNCOV
96
                testConfig = fmt.Sprintf(testConfig, "localhost", "localhost", "localhost")
×
97
        }
UNCOV
98
        cfg := []byte(testConfig)
×
UNCOV
99
        return cfg
×
100
}
101

UNCOV
102
func InitTestConfig(platform string) {
×
UNCOV
103
        // fake filesystem
×
UNCOV
104
        fs := afero.NewMemMapFs()
×
UNCOV
105
        configYaml := NewTestConfig(platform)
×
UNCOV
106
        err := afero.WriteFile(fs, config.HomeConfigFile, configYaml, perm)
×
UNCOV
107
        config.InitConfig(fs)
×
UNCOV
108
        if err != nil {
×
109
                panic(err)
×
110
        }
111
}
112

113
// StringContains Verify if the string t contains all the substring part of tt
UNCOV
114
func StringContains(tt []string, t string) bool {
×
UNCOV
115
        for _, tUnit := range tt {
×
UNCOV
116
                if !strings.Contains(t, tUnit) {
×
117
                        return false
×
118
                }
×
119
        }
UNCOV
120
        return true
×
121
}
122

UNCOV
123
func MockUserInput(t *testing.T, i string) func() {
×
UNCOV
124
        input := []byte(i)
×
UNCOV
125
        r, w, err := os.Pipe()
×
UNCOV
126
        require.NoError(t, err)
×
UNCOV
127
        _, err = w.Write(input)
×
UNCOV
128
        if err != nil {
×
129
                t.Error(err)
×
130
        }
×
UNCOV
131
        w.Close()
×
UNCOV
132

×
UNCOV
133
        // set os.Stdin = new stdin, and return function to defer in the test
×
UNCOV
134
        realStdin := os.Stdin
×
UNCOV
135
        os.Stdin = r
×
UNCOV
136
        return func() { os.Stdin = realStdin }
×
137
}
138

139
// This handles a bug in ginkgo when testing cobra commands. Essentially when no arguments are supplied
140
// Cobra uses os.Args[1:] as the arguments to the command. This causes a panic when os.Args is empty or
141
// if it contains a ginkgo argument.
UNCOV
142
func SetupOSArgsForGinkgo() func() {
×
UNCOV
143
        origArgs := os.Args
×
UNCOV
144
        newArgs := []string{}
×
UNCOV
145
        for i := range origArgs {
×
UNCOV
146
                if !(strings.Contains(origArgs[i], "ginkgo") || strings.Contains(origArgs[i], "test")) {
×
UNCOV
147
                        newArgs = append(newArgs, origArgs[i])
×
UNCOV
148
                }
×
149
        }
UNCOV
150
        if len(os.Args) > 1 {
×
UNCOV
151
                os.Args = newArgs
×
UNCOV
152
        } else {
×
UNCOV
153
                os.Args = []string{"single-arg-for-cobra"}
×
UNCOV
154
        }
×
UNCOV
155
        return func() {
×
UNCOV
156
                os.Args = origArgs
×
UNCOV
157
        }
×
158
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc