-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding support for log persistence to global_config (#182)
- Loading branch information
Showing
4 changed files
with
155 additions
and
0 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
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 raw | ||
|
||
import ( | ||
validation "github.com/go-ozzo/ozzo-validation" | ||
"github.com/runatlantis/atlantis/server/core/config/valid" | ||
) | ||
|
||
type Jobs struct { | ||
StorageBackend *StorageBackend `yaml:"storage-backend" json:"storage-backend"` | ||
} | ||
|
||
type StorageBackend struct { | ||
S3 *S3 `yaml:"s3" json:"s3"` | ||
} | ||
|
||
type S3 struct { | ||
BucketName string `yaml:"bucket-name" json:"bucket-name"` | ||
} | ||
|
||
func (j Jobs) Validate() error { | ||
return validation.ValidateStruct(&j, | ||
validation.Field(&j.StorageBackend), | ||
) | ||
} | ||
|
||
func (s StorageBackend) Validate() error { | ||
return validation.ValidateStruct(&s, | ||
validation.Field(&s.S3), | ||
) | ||
} | ||
|
||
func (s S3) Validate() error { | ||
return validation.ValidateStruct(&s, | ||
validation.Field(&s.BucketName, validation.Required), | ||
) | ||
} | ||
|
||
func (j *Jobs) ToValid() valid.Jobs { | ||
if j.StorageBackend != nil { | ||
return valid.Jobs{ | ||
StorageBackend: &valid.StorageBackend{ | ||
S3: &valid.S3{ | ||
BucketName: j.StorageBackend.S3.BucketName, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
return valid.Jobs{} | ||
} |
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,89 @@ | ||
package raw_test | ||
|
||
import ( | ||
"encoding/json" | ||
"testing" | ||
|
||
"github.com/runatlantis/atlantis/server/core/config/raw" | ||
"github.com/stretchr/testify/assert" | ||
yaml "gopkg.in/yaml.v2" | ||
) | ||
|
||
func TestJobs_Unmarshal(t *testing.T) { | ||
t.Run("yaml", func(t *testing.T) { | ||
|
||
rawYaml := ` | ||
storage-backend: | ||
s3: | ||
bucket-name: atlantis-test | ||
` | ||
|
||
var result raw.Jobs | ||
|
||
err := yaml.UnmarshalStrict([]byte(rawYaml), &result) | ||
assert.NoError(t, err) | ||
}) | ||
|
||
t.Run("json", func(t *testing.T) { | ||
rawJSON := ` | ||
{ | ||
"storage-backend": { | ||
"s3": { | ||
"bucket-name": "atlantis-test" | ||
} | ||
} | ||
} | ||
` | ||
|
||
var result raw.Jobs | ||
|
||
err := json.Unmarshal([]byte(rawJSON), &result) | ||
assert.NoError(t, err) | ||
}) | ||
} | ||
|
||
func TestJobs_Validate_Success(t *testing.T) { | ||
cases := []struct { | ||
description string | ||
subject raw.Jobs | ||
}{ | ||
{ | ||
description: "success", | ||
subject: raw.Jobs{ | ||
StorageBackend: &raw.StorageBackend{ | ||
S3: &raw.S3{ | ||
BucketName: "test-bucket", | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
for _, c := range cases { | ||
t.Run(c.description, func(t *testing.T) { | ||
assert.NoError(t, c.subject.Validate()) | ||
}) | ||
} | ||
} | ||
|
||
func TestJobs_ValidateError(t *testing.T) { | ||
cases := []struct { | ||
description string | ||
subject raw.Jobs | ||
}{ | ||
{ | ||
description: "bucket name not specified", | ||
subject: raw.Jobs{ | ||
StorageBackend: &raw.StorageBackend{ | ||
S3: &raw.S3{}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
for _, c := range cases { | ||
t.Run(c.description, func(t *testing.T) { | ||
assert.Error(t, c.subject.Validate()) | ||
}) | ||
} | ||
} |
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