Skip to content

Commit

Permalink
Adding go tools scripts - part 1 (#573)
Browse files Browse the repository at this point in the history
* Added hack scripts for katib.

* Run ./hack/update-gofmt.sh.
  • Loading branch information
gyliu513 authored and k8s-ci-robot committed May 23, 2019
1 parent cc5f367 commit 206108a
Show file tree
Hide file tree
Showing 13 changed files with 257 additions and 73 deletions.
4 changes: 2 additions & 2 deletions cmd/manager/v1alpha1/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ func TestGetStudies(t *testing.T) {
s := &server{}
dbIf = mockDB
sc := []*api.StudyConfig{
&api.StudyConfig{
{
Name: "test1",
Owner: "admin",
OptimizationType: 1,
ObjectiveValueName: "obj_name1",
},
&api.StudyConfig{
{
Name: "test2",
Owner: "admin",
OptimizationType: 1,
Expand Down
80 changes: 40 additions & 40 deletions cmd/manager/v1alpha2/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,15 +118,15 @@ func TestGetExperimentList(t *testing.T) {
req := &api_pb.GetExperimentListRequest{}

testExpList := []*api_pb.ExperimentSummary{
&api_pb.ExperimentSummary{
{
ExperimentName: "test1",
Status: &api_pb.ExperimentStatus{
Condition: api_pb.ExperimentStatus_CREATED,
StartTime: "2019-02-03T04:05:06+09:00",
CompletionTime: "",
},
},
&api_pb.ExperimentSummary{
{
ExperimentName: "test2",
Status: &api_pb.ExperimentStatus{
Condition: api_pb.ExperimentStatus_SUCCEEDED,
Expand Down Expand Up @@ -177,11 +177,11 @@ func TestUpdateAlgorithmExtraSettings(t *testing.T) {
req := &api_pb.UpdateAlgorithmExtraSettingsRequest{
ExperimentName: "test1",
ExtraAlgorithmSettings: []*api_pb.AlgorithmSetting{
&api_pb.AlgorithmSetting{
{
Name: "set1",
Value: "10",
},
&api_pb.AlgorithmSetting{
{
Name: "set2",
Value: "0.5",
},
Expand All @@ -205,11 +205,11 @@ func TestGetAlgorithmExtraSettings(t *testing.T) {
ExperimentName: "test1",
}
extraAlgoSets := []*api_pb.AlgorithmSetting{
&api_pb.AlgorithmSetting{
{
Name: "set1",
Value: "10",
},
&api_pb.AlgorithmSetting{
{
Name: "set2",
Value: "0.5",
},
Expand Down Expand Up @@ -239,11 +239,11 @@ func TestRegisterTrial(t *testing.T) {
RunSpec: "",
ParameterAssignments: &api_pb.TrialSpec_ParameterAssignments{
Assignments: []*api_pb.ParameterAssignment{
&api_pb.ParameterAssignment{
{
Name: "param1",
Value: "10",
},
&api_pb.ParameterAssignment{
{
Name: "param2",
Value: "0.1",
},
Expand All @@ -256,19 +256,19 @@ func TestRegisterTrial(t *testing.T) {
CompletionTime: "",
Observation: &api_pb.Observation{
Metrics: []*api_pb.Metric{
&api_pb.Metric{
{
Name: "f1_score",
Value: "88.95",
},
&api_pb.Metric{
{
Name: "loss",
Value: "0.5",
},
&api_pb.Metric{
{
Name: "precision",
Value: "88.7",
},
&api_pb.Metric{
{
Name: "recall",
Value: "89.2",
},
Expand Down Expand Up @@ -313,18 +313,18 @@ func TestGetTrialList(t *testing.T) {
Filter: "trial",
}
trialList := []*api_pb.Trial{
&api_pb.Trial{
{
Name: "test1-trial1",
Spec: &api_pb.TrialSpec{
ExperimentName: "test1",
RunSpec: "",
ParameterAssignments: &api_pb.TrialSpec_ParameterAssignments{
Assignments: []*api_pb.ParameterAssignment{
&api_pb.ParameterAssignment{
{
Name: "param1",
Value: "10",
},
&api_pb.ParameterAssignment{
{
Name: "param2",
Value: "0.1",
},
Expand All @@ -337,38 +337,38 @@ func TestGetTrialList(t *testing.T) {
CompletionTime: "",
Observation: &api_pb.Observation{
Metrics: []*api_pb.Metric{
&api_pb.Metric{
{
Name: "f1_score",
Value: "88.95",
},
&api_pb.Metric{
{
Name: "loss",
Value: "0.5",
},
&api_pb.Metric{
{
Name: "precision",
Value: "88.7",
},
&api_pb.Metric{
{
Name: "recall",
Value: "89.2",
},
},
},
},
},
&api_pb.Trial{
{
Name: "test1-trial2",
Spec: &api_pb.TrialSpec{
ExperimentName: "test1",
RunSpec: "",
ParameterAssignments: &api_pb.TrialSpec_ParameterAssignments{
Assignments: []*api_pb.ParameterAssignment{
&api_pb.ParameterAssignment{
{
Name: "param1",
Value: "20",
},
&api_pb.ParameterAssignment{
{
Name: "param2",
Value: "0.5",
},
Expand Down Expand Up @@ -413,11 +413,11 @@ func TestGetTrial(t *testing.T) {
RunSpec: "",
ParameterAssignments: &api_pb.TrialSpec_ParameterAssignments{
Assignments: []*api_pb.ParameterAssignment{
&api_pb.ParameterAssignment{
{
Name: "param1",
Value: "10",
},
&api_pb.ParameterAssignment{
{
Name: "param2",
Value: "0.1",
},
Expand All @@ -430,19 +430,19 @@ func TestGetTrial(t *testing.T) {
CompletionTime: "",
Observation: &api_pb.Observation{
Metrics: []*api_pb.Metric{
&api_pb.Metric{
{
Name: "f1_score",
Value: "88.95",
},
&api_pb.Metric{
{
Name: "loss",
Value: "0.5",
},
&api_pb.Metric{
{
Name: "precision",
Value: "88.7",
},
&api_pb.Metric{
{
Name: "recall",
Value: "89.2",
},
Expand Down Expand Up @@ -475,19 +475,19 @@ func TestUpdateTrialStatus(t *testing.T) {
CompletionTime: "2019-02-03T05:05:06+09:00",
Observation: &api_pb.Observation{
Metrics: []*api_pb.Metric{
&api_pb.Metric{
{
Name: "f1_score",
Value: "88.95",
},
&api_pb.Metric{
{
Name: "loss",
Value: "0.5",
},
&api_pb.Metric{
{
Name: "precision",
Value: "88.7",
},
&api_pb.Metric{
{
Name: "recall",
Value: "89.2",
},
Expand All @@ -513,28 +513,28 @@ func TestReportObservationLog(t *testing.T) {
TrialName: "test1-trial1",
ObservationLog: &api_pb.ObservationLog{
MetricLogs: []*api_pb.MetricLog{
&api_pb.MetricLog{
{
TimeStamp: "2019-02-03T04:05:06+09:00",
Metric: &api_pb.Metric{
Name: "f1_score",
Value: "88.95",
},
},
&api_pb.MetricLog{
{
TimeStamp: "2019-02-03T04:05:06+09:00",
Metric: &api_pb.Metric{
Name: "loss",
Value: "0.5",
},
},
&api_pb.MetricLog{
{
TimeStamp: "2019-02-03T04:05:06+09:00",
Metric: &api_pb.Metric{
Name: "precision",
Value: "88.7",
},
},
&api_pb.MetricLog{
{
TimeStamp: "2019-02-03T04:05:06+09:00",
Metric: &api_pb.Metric{
Name: "recall",
Expand Down Expand Up @@ -566,28 +566,28 @@ func TestGetObservationLog(t *testing.T) {

obs := &api_pb.ObservationLog{
MetricLogs: []*api_pb.MetricLog{
&api_pb.MetricLog{
{
TimeStamp: "2019-02-03T04:05:06+09:00",
Metric: &api_pb.Metric{
Name: "f1_score",
Value: "88.95",
},
},
&api_pb.MetricLog{
{
TimeStamp: "2019-02-03T04:05:06+09:00",
Metric: &api_pb.Metric{
Name: "loss",
Value: "0.5",
},
},
&api_pb.MetricLog{
{
TimeStamp: "2019-02-03T04:05:06+09:00",
Metric: &api_pb.Metric{
Name: "precision",
Value: "88.7",
},
},
&api_pb.MetricLog{
{
TimeStamp: "2019-02-03T04:05:06+09:00",
Metric: &api_pb.Metric{
Name: "recall",
Expand Down
Empty file added hack/.golint_failures
Empty file.
21 changes: 21 additions & 0 deletions hack/update-gofmt.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash

# Copyright 2019 The Kubeflow Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

set -o errexit
set -o nounset
set -o pipefail

find . -name "*.go" | grep -v "\/vendor\/" | xargs gofmt -s -w
31 changes: 31 additions & 0 deletions hack/verify-gofmt.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/env bash
# Copyright 2019 The Kubeflow Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

set -o errexit
set -o nounset
set -o pipefail

if ! which gofmt > /dev/null; then
echo "Can not find gofmt"
exit 1
fi

diff=$(find . -name "*.go" | grep -v "\/vendor\/" | xargs gofmt -s -d 2>&1)
if [[ -n "${diff}" ]]; then
echo "${diff}"
echo
echo "Please run hack/update-gofmt.sh"
exit 1
fi
Loading

0 comments on commit 206108a

Please sign in to comment.