weldr: move common.ComposeState to weldr

ComposeState is only used by the weldr API.

Drop the JSON marshaller and unmarshaller, because ComposeState is not
used in an JSON-exported field anymore.
This commit is contained in:
Lars Karlitski 2020-10-24 13:40:08 +02:00
parent 669b612d96
commit bcd57a77e2
5 changed files with 62 additions and 67 deletions

View file

@ -69,31 +69,3 @@ func (ibs *ImageBuildState) UnmarshalJSON(data []byte) error {
func (ibs ImageBuildState) MarshalJSON() ([]byte, error) {
return json.Marshal(getStateMapping()[ibs])
}
type ComposeState int
const (
CWaiting ComposeState = iota
CRunning
CFinished
CFailed
)
// ToString converts ImageBuildState into a human readable string
func (cs ComposeState) ToString() string {
return getStateMapping()[int(cs)]
}
// UnmarshalJSON converts a JSON string into an ImageBuildState
func (ibs *ComposeState) UnmarshalJSON(data []byte) error {
val, err := unmarshalStateHelper(data, getStateMapping())
if err != nil {
return err
}
*ibs = ComposeState(val)
return nil
}
func (ibs ComposeState) MarshalJSON() ([]byte, error) {
return json.Marshal(getStateMapping()[ibs])
}

View file

@ -2,28 +2,26 @@ package common
import (
"encoding/json"
"github.com/stretchr/testify/assert"
"testing"
"github.com/stretchr/testify/assert"
)
func TestJSONConversions(t *testing.T) {
type TestJson struct {
Ibs ImageBuildState `json:"ibs"`
Cs ComposeState `json:"cs"`
}
typedCases := []TestJson{
{
Ibs: IBWaiting,
Cs: CWaiting,
},
{
Ibs: IBRunning,
Cs: CFailed,
},
}
strCases := []string{
`{"ibs": "WAITING", "cs": "WAITING"}`,
`{"ibs": "RUNNING", "cs": "FAILED"}`,
`{"ibs": "WAITING"}`,
`{"ibs": "RUNNING"}`,
}
for n, c := range strCases {