-
Notifications
You must be signed in to change notification settings - Fork 31
New Build Feature: Golang #80
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
cvbarros
merged 3 commits into
cvbarros:master
from
tombuildsstuff:f/build-feature-golang
Apr 29, 2020
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| package teamcity | ||
|
|
||
| import ( | ||
| "encoding/json" | ||
| ) | ||
|
|
||
| //FeatureCommitStatusPublisher represents a golang build feature. Implements BuildFeature interface | ||
| type FeatureGolangPublisher struct { | ||
| id string | ||
| disabled bool | ||
| buildTypeID string | ||
|
|
||
| properties *Properties | ||
| } | ||
|
|
||
| // NewFeatureGolang returns a new instance of the FeatureGolangPublisher struct | ||
| func NewFeatureGolang() *FeatureGolangPublisher { | ||
| return &FeatureGolangPublisher{ | ||
| properties: NewProperties(), | ||
| } | ||
| } | ||
|
|
||
| //ID returns the ID for this instance. | ||
| func (f *FeatureGolangPublisher) ID() string { | ||
| return f.id | ||
| } | ||
|
|
||
| //SetID sets the ID for this instance. | ||
| func (f *FeatureGolangPublisher) SetID(value string) { | ||
| f.id = value | ||
| } | ||
|
|
||
| //Type returns the "commit-status-publisher", the keyed-type for this build feature instance | ||
| func (f *FeatureGolangPublisher) Type() string { | ||
| return "golang" | ||
| } | ||
|
|
||
| //Disabled returns whether this build feature is disabled or not. | ||
| func (f *FeatureGolangPublisher) Disabled() bool { | ||
| return f.disabled | ||
| } | ||
|
|
||
| //SetDisabled sets whether this build feature is disabled or not. | ||
| func (f *FeatureGolangPublisher) SetDisabled(value bool) { | ||
| f.disabled = value | ||
| } | ||
|
|
||
| //BuildTypeID is a getter for the Build Type ID associated with this build feature. | ||
| func (f *FeatureGolangPublisher) BuildTypeID() string { | ||
| return f.buildTypeID | ||
| } | ||
|
|
||
| //SetBuildTypeID is a setter for the Build Type ID associated with this build feature. | ||
| func (f *FeatureGolangPublisher) SetBuildTypeID(value string) { | ||
| f.buildTypeID = value | ||
| } | ||
|
|
||
| //Properties returns a *Properties instance representing a serializable collection to be used. | ||
| func (f *FeatureGolangPublisher) Properties() *Properties { | ||
| return f.properties | ||
| } | ||
|
|
||
| //MarshalJSON implements JSON serialization for FeatureCommitStatusPublisher | ||
| func (f *FeatureGolangPublisher) MarshalJSON() ([]byte, error) { | ||
| out := &buildFeatureJSON{ | ||
| ID: f.id, | ||
| Disabled: NewBool(f.disabled), | ||
| Properties: f.properties, | ||
| Inherited: NewFalse(), | ||
| Type: f.Type(), | ||
| } | ||
|
|
||
| // this is the only value and has to be set to this - no no point making it user configurable | ||
| out.Properties.AddOrReplaceValue("test.format", "json") | ||
| return json.Marshal(out) | ||
| } | ||
|
|
||
| //UnmarshalJSON implements JSON deserialization for FeatureCommitStatusPublisher | ||
| func (f *FeatureGolangPublisher) UnmarshalJSON(data []byte) error { | ||
| var aux buildFeatureJSON | ||
| if err := json.Unmarshal(data, &aux); err != nil { | ||
| return err | ||
| } | ||
| f.id = aux.ID | ||
|
|
||
| disabled := aux.Disabled | ||
| if disabled == nil { | ||
| disabled = NewFalse() | ||
| } | ||
| f.disabled = *disabled | ||
| f.properties = NewProperties(aux.Properties.Items...) | ||
|
|
||
| return nil | ||
| } |
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,59 @@ | ||
| package teamcity_test | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "testing" | ||
| "time" | ||
|
|
||
| "github.com/cvbarros/go-teamcity/teamcity" | ||
| "github.com/stretchr/testify/assert" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| func TestFeatureGolang_Lifecycle(t *testing.T) { | ||
| name := fmt.Sprintf("Project %d", time.Now().Unix()) | ||
| newProject := getTestProjectData(name, "") | ||
| client := setup() | ||
|
|
||
| project, err := client.Projects.Create(newProject) | ||
| require.NoError(t, err) | ||
| defer cleanUpProject(t, client, project.ID) | ||
|
|
||
| buildType, err := teamcity.NewBuildType(project.ID, "Hello") | ||
| require.NoError(t, err) | ||
| buildConfig, err := client.BuildTypes.Create(buildType) | ||
| require.NoError(t, err) | ||
|
|
||
| service := client.BuildFeatureService(buildConfig.ID) | ||
| feature := teamcity.NewFeatureGolang() | ||
| feature.SetBuildTypeID(buildConfig.ID) | ||
| createdService, err := service.Create(feature) | ||
| require.NoError(t, err) | ||
|
|
||
| retrievedService, err := service.GetByID(createdService.ID()) | ||
| require.NoError(t, err) | ||
| assert.False(t, retrievedService.Disabled()) | ||
| } | ||
|
|
||
| func TestFeatureGolang_UnmarshallProperties(t *testing.T) { | ||
| assert := assert.New(t) | ||
| var actual teamcity.FeatureGolangPublisher | ||
| const json = ` | ||
| { | ||
| "id": "BUILD_EXT_1", | ||
| "type": "golang", | ||
| "properties": { | ||
| "count": 1, | ||
| "property": [ | ||
| { | ||
| "name": "test.format", | ||
| "value": "json" | ||
| } | ||
| ] | ||
| } | ||
| } | ||
| ` | ||
| actual.UnmarshalJSON([]byte(json)) | ||
|
|
||
| assert.Equal("BUILD_EXT_1", actual.ID()) | ||
| } |
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.