-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add restful service to VFKit which defaults to `tcp://localhost:8081`. The URL can be changed using the newly introduced --restful-uri option. The schemes may be `tcp` or `unix` (unix domain socket). The service for the unix domain implementation is incomplete and should be considered a TODO still. users can also opt out of the service with a `--restful-uri none`. the restful service now replies to three endpoints: /vm/state GET which returns the state of the vm /vm/state POST which allows for a state change /vm/inspect GET which returns basic information about the virtual machine error handling for the endpoints needs to be completed still. these endpoints should return http response codes (like 200) based on the error handling. this can be completed in a subsequent PR. /version GET should also probably be added. I was unsure if we should return the version of vfkit (my first inclination) or some sort of API version. maybe we should return both? --log-level option added which can be set to 'debug' or 'error' or other well known log levels added tests for new content where applicable Signed-off-by: Brent Baude <brentbaude@Brents-Mini-2.localdomain>
- Loading branch information
Brent Baude
authored and
Brent Baude
committed
Apr 23, 2023
1 parent
223460b
commit d87afd0
Showing
15 changed files
with
682 additions
and
13 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
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
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
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,64 @@ | ||
package cmdline | ||
|
||
import "testing" | ||
|
||
func Test_validateRestfulURI(t *testing.T) { | ||
type args struct { | ||
inputURI string | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
wantErr bool | ||
}{ | ||
{ | ||
name: "valid tcp", | ||
args: args{ | ||
inputURI: "tcp://localhost:8080", | ||
}, | ||
wantErr: false, | ||
}, | ||
{ | ||
name: "invalid tcp - no host", | ||
args: args{ | ||
inputURI: "tcp://", | ||
}, | ||
wantErr: true, | ||
}, | ||
{ | ||
name: "invalid scheme", | ||
args: args{ | ||
inputURI: "http://localhost", | ||
}, | ||
wantErr: true, | ||
}, | ||
{ | ||
name: "valid uds", | ||
args: args{ | ||
inputURI: "unix:///my/socket/goes/here/vfkit.sock", | ||
}, | ||
wantErr: false, | ||
}, | ||
{ | ||
name: "invalid uds - no host", | ||
args: args{ | ||
inputURI: "unix://", | ||
}, | ||
wantErr: true, | ||
}, | ||
{ | ||
name: "none", | ||
args: args{ | ||
inputURI: "none://", | ||
}, | ||
wantErr: false, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
if err := validateRestfulURI(tt.args.inputURI); (err != nil) != tt.wantErr { | ||
t.Errorf("validateRestfulURI() error = %v, wantErr %v", err, tt.wantErr) | ||
} | ||
}) | ||
} | ||
} |
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
Oops, something went wrong.