From 58797626e07edb3e436f619fc59e3b09216885d3 Mon Sep 17 00:00:00 2001 From: Ronen Lubin Date: Thu, 9 Jan 2025 14:26:59 +0200 Subject: [PATCH 1/6] support using atlas hcl file in monitor action --- .github/workflows/ci-go.yaml | 8 ++++++- README.md | 5 ++++- atlasaction/action.go | 43 +++++++++++++++++++++++++----------- atlasaction/action_test.go | 29 +++++++++++++++++++++--- monitor/schema/action.yml | 12 ++++++++-- monitor/schema/atlas.hcl | 4 ++++ 6 files changed, 81 insertions(+), 20 deletions(-) create mode 100644 monitor/schema/atlas.hcl diff --git a/.github/workflows/ci-go.yaml b/.github/workflows/ci-go.yaml index 1b8395d0..fc6d6908 100644 --- a/.github/workflows/ci-go.yaml +++ b/.github/workflows/ci-go.yaml @@ -444,9 +444,15 @@ jobs: - run: go install ./cmd/atlas-action env: CGO_ENABLED: 0 - - id: sanity + - name: sanity using url uses: ./monitor/schema with: cloud-token: ${{ secrets.ATLAS_AGENT_TOKEN }} url: 'mysql://root:pass@localhost:3306/dev' slug: 'github-action' + - name: sanity using config + uses: ./monitor/schema + with: + cloud-token: ${{ secrets.ATLAS_AGENT_TOKEN }} + config: 'file://monitor/schema/atlas.hcl' + env: 'dev' diff --git a/README.md b/README.md index 03288217..852a82d1 100644 --- a/README.md +++ b/README.md @@ -459,7 +459,10 @@ Can be used periodically to [monitor](https://atlasgo.io/monitoring) changes in * `cloud-token` - (required) The Atlas Cloud token to use for authentication. To create a cloud token see the [docs](https://atlasgo.io/cloud/bots). -* `url` - (required) The URL of the database to monitor. For example: `mysql://root:pass@localhost:3306/prod`. +* `url` - (optional) The URL of the database to monitor. For example: `mysql://root:pass@localhost:3306/prod` (mutually exclusive with `config` and `env`). +* `config` - (optional) The URL of the Atlas configuration file. By default, Atlas will look for a file + named `atlas.hcl` in the current directory. For example, `file://config/atlas.hcl` (mutually exclusive with `url`). +* `env` - (optional) The environment to use from the Atlas configuration file. For example, `dev` (mutually exclusive with `url`). * `slug` - (optional) Unique identifier for the database server. * `schemas` - (optional) List of database schemas to include (by default includes all schemas). see: https://atlasgo.io/declarative/inspect#inspect-multiple-schemas. * `exclude` - (optional) List of exclude patterns from inspection. see: https://atlasgo.io/declarative/inspect#exclude-schemas. diff --git a/atlasaction/action.go b/atlasaction/action.go index 873eff97..d96d8c90 100644 --- a/atlasaction/action.go +++ b/atlasaction/action.go @@ -820,6 +820,13 @@ func (a *Actions) MonitorSchema(ctx context.Context) error { if err != nil { return err } + var ( + config = a.GetInput("config") + env = a.GetInput("env") + ) + if (config != "" || env != "") && db.String() != "" { + return errors.New("only one of the inputs 'config' or 'url' should be provided") + } var ( id = cloud.ScopeIdent{ URL: db.Redacted(), @@ -833,15 +840,30 @@ func (a *Actions) MonitorSchema(ctx context.Context) error { }); err != nil { return fmt.Errorf("failed to login to Atlas Cloud: %w", err) } - res, err := a.Atlas.SchemaInspect(ctx, &atlasexec.SchemaInspectParams{ - URL: db.String(), + params := &atlasexec.SchemaInspectParams{ Schema: id.Schemas, Exclude: id.Schemas, - Format: `{{ printf "# %s\n%s" .Hash .MarshalHCL }}`, - }) + Format: `{{ printf "# %s\n%s\n%s" .Hash .MarshalHCL .RedactedURL }}`, + } + if db.String() != "" { + params.URL = db.String() + } + if config != "" { + params.ConfigURL = config + params.Env = env + } + res, err := a.Atlas.SchemaInspect(ctx, params) if err != nil { return fmt.Errorf("failed to inspect the schema: %w", err) } + var ( + parts = strings.SplitN(res, "\n", 3) + hash = strings.TrimPrefix(parts[0], "# ") + hcl = parts[1] + ) + if id.URL == "" { + id.URL = parts[2] // Get the URL from the inspect output. + } cc, err := a.cloudClient(ctx, "cloud-token") if err != nil { return err @@ -850,15 +872,10 @@ func (a *Actions) MonitorSchema(ctx context.Context) error { if err != nil { return fmt.Errorf("failed to get the schema snapshot hash: %w", err) } - var ( - parts = strings.SplitN(res, "\n", 2) - hash = strings.TrimPrefix(parts[0], "# ") - hcl = parts[1] - input = &cloud.PushSnapshotInput{ - ScopeIdent: id, - HashMatch: strings.HasPrefix(h, "h1:") && OldAgentHash(hcl) == h || hash == h, - } - ) + input := &cloud.PushSnapshotInput{ + ScopeIdent: id, + HashMatch: strings.HasPrefix(h, "h1:") && OldAgentHash(hcl) == h || hash == h, + } if !input.HashMatch { input.Snapshot = &cloud.SnapshotInput{Hash: hash, HCL: hcl} } diff --git a/atlasaction/action_test.go b/atlasaction/action_test.go index 6a63a5c1..d9edc0f5 100644 --- a/atlasaction/action_test.go +++ b/atlasaction/action_test.go @@ -555,11 +555,12 @@ func TestMonitorSchema(t *testing.T) { ctx = context.Background() ) for _, tt := range []struct { - name, url, slug string + name, url, slug, config string schemas, exclude []string latestHash, newHash, hcl string exSnapshot *cloud.SnapshotInput exMatch bool + wantErr bool }{ { name: "no latest hash", @@ -628,6 +629,22 @@ func TestMonitorSchema(t *testing.T) { exclude: []string{"foo.*", "bar.*.*"}, exMatch: true, }, + { + name: "url and config should rerurn error", + url: u, + config: "config", + wantErr: true, + }, + { + name: "hash match old hash func, using config", + config: "file:/atlas.hcl", + latestHash: atlasaction.OldAgentHash("hcl"), + newHash: "hash", + hcl: "hcl", + schemas: []string{}, + exclude: []string{}, + exMatch: true, + }, } { t.Run(tt.name, func(t *testing.T) { var ( @@ -637,6 +654,7 @@ func TestMonitorSchema(t *testing.T) { "cloud-token": "token", "url": tt.url, "slug": tt.slug, + "config": tt.config, "schemas": strings.Join(tt.schemas, "\n"), "exclude": strings.Join(tt.exclude, "\n"), }, @@ -647,7 +665,7 @@ func TestMonitorSchema(t *testing.T) { return nil }, schemaInspect: func(_ context.Context, p *atlasexec.SchemaInspectParams) (string, error) { - return fmt.Sprintf("# %s\n%s", tt.newHash, tt.hcl), nil + return fmt.Sprintf("# %s\n%s\n%s", tt.newHash, tt.hcl, ""), nil }, } cc = &mockCloudClient{hash: tt.latestHash} @@ -660,7 +678,12 @@ func TestMonitorSchema(t *testing.T) { ) ) require.NoError(t, err) - require.NoError(t, as.MonitorSchema(ctx)) + err = as.MonitorSchema(ctx) + if tt.wantErr { + require.Error(t, err) + return + } + require.NoError(t, err) require.Equal(t, &cloud.PushSnapshotInput{ ScopeIdent: cloud.ScopeIdent{ URL: must(url.Parse(tt.url)).Redacted(), diff --git a/monitor/schema/action.yml b/monitor/schema/action.yml index 51475bf0..dee21728 100644 --- a/monitor/schema/action.yml +++ b/monitor/schema/action.yml @@ -8,8 +8,16 @@ inputs: description: 'The token that is used to connect to Atlas Cloud (should be passed as a secret).' required: true url: - description: 'URL of the database to sync.' - required: true + description: 'URL of the database to sync (mutually exclusive with `config` and `env`).' + required: false + config: + description: 'The URL of the Atlas configuration file (mutually exclusive with `url`). + For example, `file://config/atlas.hcl`, learn more about [Atlas configuration files](https://atlasgo.io/atlas-schema/projects).' + required: false + env: + description: 'The environment to use from the Atlas configuration file. For example, `dev` + (mutually exclusive with `url`).' + required: false slug: description: 'Optional unique identifier for the database server.' required: false diff --git a/monitor/schema/atlas.hcl b/monitor/schema/atlas.hcl new file mode 100644 index 00000000..c27d5709 --- /dev/null +++ b/monitor/schema/atlas.hcl @@ -0,0 +1,4 @@ +# used in monitor github action for integration tests +env "dev" { + url = "mysql://root:pass@localhost:3306/dev" +} From c74e0c579407642fd7b5a757cb506f5ab48fba5a Mon Sep 17 00:00:00 2001 From: Ronen Lubin Date: Thu, 9 Jan 2025 14:42:08 +0200 Subject: [PATCH 2/6] temp --- atlasaction/action.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/atlasaction/action.go b/atlasaction/action.go index d96d8c90..7efa7fea 100644 --- a/atlasaction/action.go +++ b/atlasaction/action.go @@ -856,8 +856,12 @@ func (a *Actions) MonitorSchema(ctx context.Context) error { if err != nil { return fmt.Errorf("failed to inspect the schema: %w", err) } + fmt.Println("result is:\n", res) + parts := strings.SplitN(res, "\n", 3) + for _, p := range parts { + fmt.Println("part is:\n", p) + } var ( - parts = strings.SplitN(res, "\n", 3) hash = strings.TrimPrefix(parts[0], "# ") hcl = parts[1] ) From e8de595d557f56350b1e6dd8c29796dc539b74a1 Mon Sep 17 00:00:00 2001 From: Ronen Lubin Date: Thu, 9 Jan 2025 14:54:27 +0200 Subject: [PATCH 3/6] fix schema inspect format --- atlasaction/action.go | 43 ++++++++++++++++++++------------------ atlasaction/action_test.go | 2 +- 2 files changed, 24 insertions(+), 21 deletions(-) diff --git a/atlasaction/action.go b/atlasaction/action.go index 7efa7fea..e04a3fb3 100644 --- a/atlasaction/action.go +++ b/atlasaction/action.go @@ -840,10 +840,20 @@ func (a *Actions) MonitorSchema(ctx context.Context) error { }); err != nil { return fmt.Errorf("failed to login to Atlas Cloud: %w", err) } + // Get the URL on the indentifier if not provided (needed for the snapshot hash). + if id.URL == "" { + if id.URL, err = a.Atlas.SchemaInspect(ctx, &atlasexec.SchemaInspectParams{ + ConfigURL: config, + Env: env, + Format: `{{ .RedactedURL }}`, + }); err != nil { + return fmt.Errorf("failed to inspect the schema: %w", err) + } + } params := &atlasexec.SchemaInspectParams{ Schema: id.Schemas, Exclude: id.Schemas, - Format: `{{ printf "# %s\n%s\n%s" .Hash .MarshalHCL .RedactedURL }}`, + Format: `{{ printf "# %s\n%s" .Hash .MarshalHCL }}`, } if db.String() != "" { params.URL = db.String() @@ -852,22 +862,6 @@ func (a *Actions) MonitorSchema(ctx context.Context) error { params.ConfigURL = config params.Env = env } - res, err := a.Atlas.SchemaInspect(ctx, params) - if err != nil { - return fmt.Errorf("failed to inspect the schema: %w", err) - } - fmt.Println("result is:\n", res) - parts := strings.SplitN(res, "\n", 3) - for _, p := range parts { - fmt.Println("part is:\n", p) - } - var ( - hash = strings.TrimPrefix(parts[0], "# ") - hcl = parts[1] - ) - if id.URL == "" { - id.URL = parts[2] // Get the URL from the inspect output. - } cc, err := a.cloudClient(ctx, "cloud-token") if err != nil { return err @@ -876,10 +870,19 @@ func (a *Actions) MonitorSchema(ctx context.Context) error { if err != nil { return fmt.Errorf("failed to get the schema snapshot hash: %w", err) } - input := &cloud.PushSnapshotInput{ - ScopeIdent: id, - HashMatch: strings.HasPrefix(h, "h1:") && OldAgentHash(hcl) == h || hash == h, + res, err := a.Atlas.SchemaInspect(ctx, params) + if err != nil { + return fmt.Errorf("failed to inspect the schema: %w", err) } + var ( + parts = strings.SplitN(res, "\n", 2) + hash = strings.TrimPrefix(parts[0], "# ") + hcl = parts[1] + input = &cloud.PushSnapshotInput{ + ScopeIdent: id, + HashMatch: strings.HasPrefix(h, "h1:") && OldAgentHash(hcl) == h || hash == h, + } + ) if !input.HashMatch { input.Snapshot = &cloud.SnapshotInput{Hash: hash, HCL: hcl} } diff --git a/atlasaction/action_test.go b/atlasaction/action_test.go index d9edc0f5..ea3b9196 100644 --- a/atlasaction/action_test.go +++ b/atlasaction/action_test.go @@ -665,7 +665,7 @@ func TestMonitorSchema(t *testing.T) { return nil }, schemaInspect: func(_ context.Context, p *atlasexec.SchemaInspectParams) (string, error) { - return fmt.Sprintf("# %s\n%s\n%s", tt.newHash, tt.hcl, ""), nil + return fmt.Sprintf("# %s\n%s", tt.newHash, tt.hcl), nil }, } cc = &mockCloudClient{hash: tt.latestHash} From 618d9b589e25562fd66ed8c66ec1ed3c31c9e807 Mon Sep 17 00:00:00 2001 From: Ronen Lubin Date: Thu, 9 Jan 2025 15:08:09 +0200 Subject: [PATCH 4/6] fix tests --- atlasaction/action_test.go | 65 ++++++++++++++++++++++++++++---------- 1 file changed, 49 insertions(+), 16 deletions(-) diff --git a/atlasaction/action_test.go b/atlasaction/action_test.go index ea3b9196..0e37d47d 100644 --- a/atlasaction/action_test.go +++ b/atlasaction/action_test.go @@ -558,6 +558,7 @@ func TestMonitorSchema(t *testing.T) { name, url, slug, config string schemas, exclude []string latestHash, newHash, hcl string + exScopeIdent cloud.ScopeIdent exSnapshot *cloud.SnapshotInput exMatch bool wantErr bool @@ -573,6 +574,11 @@ func TestMonitorSchema(t *testing.T) { Hash: "hash", HCL: "hcl", }, + exScopeIdent: cloud.ScopeIdent{ + URL: must(url.Parse(u)).Redacted(), + Schemas: []string{}, + Exclude: []string{}, + }, }, { name: "latest hash no match", @@ -586,6 +592,11 @@ func TestMonitorSchema(t *testing.T) { Hash: "hash", HCL: "hcl", }, + exScopeIdent: cloud.ScopeIdent{ + URL: must(url.Parse(u)).Redacted(), + Schemas: []string{}, + Exclude: []string{}, + }, }, { name: "hash match old hash func", @@ -596,6 +607,11 @@ func TestMonitorSchema(t *testing.T) { schemas: []string{}, exclude: []string{}, exMatch: true, + exScopeIdent: cloud.ScopeIdent{ + URL: must(url.Parse(u)).Redacted(), + Schemas: []string{}, + Exclude: []string{}, + }, }, { name: "hash match new hash func", @@ -606,6 +622,11 @@ func TestMonitorSchema(t *testing.T) { schemas: []string{}, exclude: []string{}, exMatch: true, + exScopeIdent: cloud.ScopeIdent{ + URL: must(url.Parse(u)).Redacted(), + Schemas: []string{}, + Exclude: []string{}, + }, }, { name: "with slug", @@ -617,6 +638,12 @@ func TestMonitorSchema(t *testing.T) { schemas: []string{}, exclude: []string{}, exMatch: true, + exScopeIdent: cloud.ScopeIdent{ + URL: must(url.Parse(u)).Redacted(), + ExtID: "slug", + Schemas: []string{}, + Exclude: []string{}, + }, }, { name: "with schema and exclude", @@ -628,6 +655,12 @@ func TestMonitorSchema(t *testing.T) { schemas: []string{"foo", "bar"}, exclude: []string{"foo.*", "bar.*.*"}, exMatch: true, + exScopeIdent: cloud.ScopeIdent{ + URL: must(url.Parse(u)).Redacted(), + ExtID: "slug", + Schemas: []string{"foo", "bar"}, + Exclude: []string{"foo.*", "bar.*.*"}, + }, }, { name: "url and config should rerurn error", @@ -636,14 +669,19 @@ func TestMonitorSchema(t *testing.T) { wantErr: true, }, { - name: "hash match old hash func, using config", - config: "file:/atlas.hcl", - latestHash: atlasaction.OldAgentHash("hcl"), - newHash: "hash", - hcl: "hcl", - schemas: []string{}, - exclude: []string{}, - exMatch: true, + name: "hash match old hash func, using config", + config: "file:/atlas.hcl", + latestHash: atlasaction.OldAgentHash("hcl"), + newHash: "hash", + hcl: "hcl", + schemas: []string{}, + exclude: []string{}, + exMatch: true, + exScopeIdent: cloud.ScopeIdent{ + URL: "# hash\nhcl", + Schemas: []string{}, + Exclude: []string{}, + }, }, } { t.Run(tt.name, func(t *testing.T) { @@ -685,14 +723,9 @@ func TestMonitorSchema(t *testing.T) { } require.NoError(t, err) require.Equal(t, &cloud.PushSnapshotInput{ - ScopeIdent: cloud.ScopeIdent{ - URL: must(url.Parse(tt.url)).Redacted(), - ExtID: tt.slug, - Schemas: tt.schemas, - Exclude: tt.exclude, - }, - Snapshot: tt.exSnapshot, - HashMatch: tt.exMatch, + ScopeIdent: tt.exScopeIdent, + Snapshot: tt.exSnapshot, + HashMatch: tt.exMatch, }, cc.lastInput) require.Equal(t, map[string]string{"url": "url"}, act.output) }) From 04b9dab25be9c5452a77558e41b887d492da2906 Mon Sep 17 00:00:00 2001 From: Ronen Lubin Date: Thu, 9 Jan 2025 15:16:43 +0200 Subject: [PATCH 5/6] fix schema test --- atlasaction/testdata/schema.hcl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/atlasaction/testdata/schema.hcl b/atlasaction/testdata/schema.hcl index 0c3617b3..20b9e619 100644 --- a/atlasaction/testdata/schema.hcl +++ b/atlasaction/testdata/schema.hcl @@ -1,8 +1,8 @@ table "t1" { - schema = schema.public + schema = schema.main column "c1" { type = int } } -schema "public" {} \ No newline at end of file +schema "main" {} \ No newline at end of file From 306a612d915c1330f104020590b1b7978b046d65 Mon Sep 17 00:00:00 2001 From: Ronen Lubin Date: Thu, 9 Jan 2025 16:56:22 +0200 Subject: [PATCH 6/6] cr --- atlasaction/action.go | 53 ++++++++++++++------------------------ atlasaction/action_test.go | 52 +++++++------------------------------ 2 files changed, 29 insertions(+), 76 deletions(-) diff --git a/atlasaction/action.go b/atlasaction/action.go index e04a3fb3..91ed1a7c 100644 --- a/atlasaction/action.go +++ b/atlasaction/action.go @@ -825,11 +825,10 @@ func (a *Actions) MonitorSchema(ctx context.Context) error { env = a.GetInput("env") ) if (config != "" || env != "") && db.String() != "" { - return errors.New("only one of the inputs 'config' or 'url' should be provided") + return errors.New("only one of the inputs 'config' or 'url' must be given") } var ( id = cloud.ScopeIdent{ - URL: db.Redacted(), ExtID: a.GetInput("slug"), Schemas: a.GetArrayInput("schemas"), Exclude: a.GetArrayInput("exclude"), @@ -840,28 +839,25 @@ func (a *Actions) MonitorSchema(ctx context.Context) error { }); err != nil { return fmt.Errorf("failed to login to Atlas Cloud: %w", err) } - // Get the URL on the indentifier if not provided (needed for the snapshot hash). - if id.URL == "" { - if id.URL, err = a.Atlas.SchemaInspect(ctx, &atlasexec.SchemaInspectParams{ - ConfigURL: config, - Env: env, - Format: `{{ .RedactedURL }}`, - }); err != nil { - return fmt.Errorf("failed to inspect the schema: %w", err) - } - } params := &atlasexec.SchemaInspectParams{ - Schema: id.Schemas, - Exclude: id.Schemas, - Format: `{{ printf "# %s\n%s" .Hash .MarshalHCL }}`, + URL: db.String(), + ConfigURL: config, + Env: env, + Schema: id.Schemas, + Exclude: id.Schemas, + Format: `{{ printf "# %s\n# %s\n%s" .RedactedURL .Hash .MarshalHCL }}`, } - if db.String() != "" { - params.URL = db.String() - } - if config != "" { - params.ConfigURL = config - params.Env = env + res, err := a.Atlas.SchemaInspect(ctx, params) + if err != nil { + return fmt.Errorf("failed to inspect the schema: %w", err) } + var ( + parts = strings.SplitN(res, "\n", 3) + url = strings.TrimPrefix(parts[0], "# ") // redacted URL. + hash = strings.TrimPrefix(parts[1], "# ") + hcl = parts[2] + ) + id.URL = url cc, err := a.cloudClient(ctx, "cloud-token") if err != nil { return err @@ -870,19 +866,10 @@ func (a *Actions) MonitorSchema(ctx context.Context) error { if err != nil { return fmt.Errorf("failed to get the schema snapshot hash: %w", err) } - res, err := a.Atlas.SchemaInspect(ctx, params) - if err != nil { - return fmt.Errorf("failed to inspect the schema: %w", err) + input := &cloud.PushSnapshotInput{ + ScopeIdent: id, + HashMatch: strings.HasPrefix(h, "h1:") && OldAgentHash(hcl) == h || hash == h, } - var ( - parts = strings.SplitN(res, "\n", 2) - hash = strings.TrimPrefix(parts[0], "# ") - hcl = parts[1] - input = &cloud.PushSnapshotInput{ - ScopeIdent: id, - HashMatch: strings.HasPrefix(h, "h1:") && OldAgentHash(hcl) == h || hash == h, - } - ) if !input.HashMatch { input.Snapshot = &cloud.SnapshotInput{Hash: hash, HCL: hcl} } diff --git a/atlasaction/action_test.go b/atlasaction/action_test.go index 0e37d47d..454848b7 100644 --- a/atlasaction/action_test.go +++ b/atlasaction/action_test.go @@ -16,7 +16,6 @@ import ( "log/slog" "net/http" "net/http/httptest" - "net/url" "os" "os/exec" "path/filepath" @@ -558,7 +557,6 @@ func TestMonitorSchema(t *testing.T) { name, url, slug, config string schemas, exclude []string latestHash, newHash, hcl string - exScopeIdent cloud.ScopeIdent exSnapshot *cloud.SnapshotInput exMatch bool wantErr bool @@ -574,11 +572,6 @@ func TestMonitorSchema(t *testing.T) { Hash: "hash", HCL: "hcl", }, - exScopeIdent: cloud.ScopeIdent{ - URL: must(url.Parse(u)).Redacted(), - Schemas: []string{}, - Exclude: []string{}, - }, }, { name: "latest hash no match", @@ -592,11 +585,6 @@ func TestMonitorSchema(t *testing.T) { Hash: "hash", HCL: "hcl", }, - exScopeIdent: cloud.ScopeIdent{ - URL: must(url.Parse(u)).Redacted(), - Schemas: []string{}, - Exclude: []string{}, - }, }, { name: "hash match old hash func", @@ -607,11 +595,6 @@ func TestMonitorSchema(t *testing.T) { schemas: []string{}, exclude: []string{}, exMatch: true, - exScopeIdent: cloud.ScopeIdent{ - URL: must(url.Parse(u)).Redacted(), - Schemas: []string{}, - Exclude: []string{}, - }, }, { name: "hash match new hash func", @@ -622,11 +605,6 @@ func TestMonitorSchema(t *testing.T) { schemas: []string{}, exclude: []string{}, exMatch: true, - exScopeIdent: cloud.ScopeIdent{ - URL: must(url.Parse(u)).Redacted(), - Schemas: []string{}, - Exclude: []string{}, - }, }, { name: "with slug", @@ -638,12 +616,6 @@ func TestMonitorSchema(t *testing.T) { schemas: []string{}, exclude: []string{}, exMatch: true, - exScopeIdent: cloud.ScopeIdent{ - URL: must(url.Parse(u)).Redacted(), - ExtID: "slug", - Schemas: []string{}, - Exclude: []string{}, - }, }, { name: "with schema and exclude", @@ -655,12 +627,6 @@ func TestMonitorSchema(t *testing.T) { schemas: []string{"foo", "bar"}, exclude: []string{"foo.*", "bar.*.*"}, exMatch: true, - exScopeIdent: cloud.ScopeIdent{ - URL: must(url.Parse(u)).Redacted(), - ExtID: "slug", - Schemas: []string{"foo", "bar"}, - Exclude: []string{"foo.*", "bar.*.*"}, - }, }, { name: "url and config should rerurn error", @@ -677,11 +643,6 @@ func TestMonitorSchema(t *testing.T) { schemas: []string{}, exclude: []string{}, exMatch: true, - exScopeIdent: cloud.ScopeIdent{ - URL: "# hash\nhcl", - Schemas: []string{}, - Exclude: []string{}, - }, }, } { t.Run(tt.name, func(t *testing.T) { @@ -703,7 +664,7 @@ func TestMonitorSchema(t *testing.T) { return nil }, schemaInspect: func(_ context.Context, p *atlasexec.SchemaInspectParams) (string, error) { - return fmt.Sprintf("# %s\n%s", tt.newHash, tt.hcl), nil + return fmt.Sprintf("# %s\n# %s\n%s", tt.url, tt.newHash, tt.hcl), nil }, } cc = &mockCloudClient{hash: tt.latestHash} @@ -723,9 +684,14 @@ func TestMonitorSchema(t *testing.T) { } require.NoError(t, err) require.Equal(t, &cloud.PushSnapshotInput{ - ScopeIdent: tt.exScopeIdent, - Snapshot: tt.exSnapshot, - HashMatch: tt.exMatch, + ScopeIdent: cloud.ScopeIdent{ + URL: tt.url, + ExtID: tt.slug, + Schemas: tt.schemas, + Exclude: tt.exclude, + }, + Snapshot: tt.exSnapshot, + HashMatch: tt.exMatch, }, cc.lastInput) require.Equal(t, map[string]string{"url": "url"}, act.output) })