add document state transformer interface
Some checks are pending
Lint / golangci-lint (push) Waiting to run
Declarative Tests / test (push) Waiting to run
Declarative Tests / build-fedora (push) Waiting to run
Declarative Tests / build-ubuntu-focal (push) Waiting to run

This commit is contained in:
Matthew Rich 2024-09-25 04:56:43 +00:00
parent 7440fc2610
commit 32c9d13e71
3 changed files with 19 additions and 4 deletions

View File

@ -600,7 +600,7 @@ func (c *ContainerImage) Create(ctx context.Context) (err error) {
err = c.Push(ctx) err = c.Push(ctx)
} }
} }
return nil return
} }
func (c *ContainerImage) Update(ctx context.Context) error { func (c *ContainerImage) Update(ctx context.Context) error {

View File

@ -149,7 +149,7 @@ func TestCreateContainerImagePush(t *testing.T) {
assert.Nil(t, stater.Trigger("create")) assert.Nil(t, stater.Trigger("create"))
c.Push(context.Background()) assert.Nil(t, c.Push(context.Background()))
assert.True(t, c.PushImage) assert.True(t, c.PushImage)
assert.Equal(t, "foo", c.Output.String()) assert.Equal(t, "foo", c.Output.String())
} }

View File

@ -137,41 +137,56 @@ func (r ResourceReference) ContentWriterStream() (*transport.Writer, error) {
func StorageMachine(sub machine.Subscriber) machine.Stater { func StorageMachine(sub machine.Subscriber) machine.Stater {
// start_destroy -> absent -> start_create -> present -> start_destroy // start_destroy -> absent -> start_create -> present -> start_destroy
stater := machine.New("unknown") stater := machine.New("unknown")
stater.AddStates("unkonwn", "absent", "start_create", "present", "start_delete", "start_read", "start_update") stater.AddStates("unkonwn", "absent", "start_create", "present", "start_delete", "start_read", "start_update", "start_stat")
stater.AddTransition("create", machine.States("unknown", "absent"), "start_create") stater.AddTransition("create", machine.States("unknown", "absent"), "start_create")
if e := stater.AddSubscription("create", sub); e != nil { if e := stater.AddSubscription("create", sub); e != nil {
return nil return nil
} }
stater.AddTransition("created", machine.States("start_create"), "present") stater.AddTransition("created", machine.States("start_create"), "present")
if e := stater.AddSubscription("created", sub); e != nil { if e := stater.AddSubscription("created", sub); e != nil {
return nil return nil
} }
stater.AddTransition("exists", machine.States("unknown", "absent"), "present") stater.AddTransition("exists", machine.States("unknown", "absent", "start_stat"), "present")
if e := stater.AddSubscription("exists", sub); e != nil { if e := stater.AddSubscription("exists", sub); e != nil {
return nil return nil
} }
stater.AddTransition("notexists", machine.States("*"), "absent") stater.AddTransition("notexists", machine.States("*"), "absent")
if e := stater.AddSubscription("notexists", sub); e != nil { if e := stater.AddSubscription("notexists", sub); e != nil {
return nil return nil
} }
stater.AddTransition("read", machine.States("*"), "start_read") stater.AddTransition("read", machine.States("*"), "start_read")
if e := stater.AddSubscription("read", sub); e != nil { if e := stater.AddSubscription("read", sub); e != nil {
return nil return nil
} }
stater.AddTransition("state_read", machine.States("start_read"), "present") stater.AddTransition("state_read", machine.States("start_read"), "present")
stater.AddTransition("stat", machine.States("*"), "start_stat")
if e := stater.AddSubscription("stat", sub); e != nil {
return nil
}
stater.AddTransition("update", machine.States("*"), "start_update") stater.AddTransition("update", machine.States("*"), "start_update")
if e := stater.AddSubscription("update", sub); e != nil { if e := stater.AddSubscription("update", sub); e != nil {
return nil return nil
} }
stater.AddTransition("updated", machine.States("start_update"), "present") stater.AddTransition("updated", machine.States("start_update"), "present")
stater.AddTransition("delete", machine.States("*"), "start_delete") stater.AddTransition("delete", machine.States("*"), "start_delete")
if e := stater.AddSubscription("delete", sub); e != nil { if e := stater.AddSubscription("delete", sub); e != nil {
return nil return nil
} }
stater.AddTransition("deleted", machine.States("start_delete"), "absent") stater.AddTransition("deleted", machine.States("start_delete"), "absent")
if e := stater.AddSubscription("deleted", sub); e != nil { if e := stater.AddSubscription("deleted", sub); e != nil {
return nil return nil
} }
return stater return stater
} }