Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
c3da356c
Commit
c3da356c
authored
Jun 24, 2014
by
Daniel Smith
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #237 from brendandburns/tests
Added some tests
parents
8b44f34e
60ce1296
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
90 additions
and
1 deletion
+90
-1
proxy_server_test.go
pkg/cloudcfg/proxy_server_test.go
+51
-0
resource_printer_test.go
pkg/cloudcfg/resource_printer_test.go
+39
-1
No files found.
pkg/cloudcfg/proxy_server_test.go
0 → 100644
View file @
c3da356c
/*
Copyright 2014 Google Inc. All rights reserved.
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.
*/
package
cloudcfg
import
(
"io/ioutil"
"net/http"
"net/http/httptest"
"testing"
)
func
TestFileServing
(
t
*
testing
.
T
)
{
data
:=
"This is test data"
dir
,
err
:=
ioutil
.
TempDir
(
""
,
"data"
)
expectNoError
(
t
,
err
)
err
=
ioutil
.
WriteFile
(
dir
+
"/test.txt"
,
[]
byte
(
data
),
0755
)
expectNoError
(
t
,
err
)
handler
:=
fileServer
{
prefix
:
"/foo/"
,
base
:
dir
,
}
server
:=
httptest
.
NewServer
(
&
handler
)
client
:=
http
.
Client
{}
req
,
err
:=
http
.
NewRequest
(
"GET"
,
server
.
URL
+
handler
.
prefix
+
"/test.txt"
,
nil
)
expectNoError
(
t
,
err
)
res
,
err
:=
client
.
Do
(
req
)
expectNoError
(
t
,
err
)
defer
res
.
Body
.
Close
()
b
,
err
:=
ioutil
.
ReadAll
(
res
.
Body
)
expectNoError
(
t
,
err
)
if
res
.
StatusCode
!=
http
.
StatusOK
{
t
.
Errorf
(
"Unexpected status: %d"
,
res
.
StatusCode
)
}
if
string
(
b
)
!=
data
{
t
.
Errorf
(
"Data doesn't match: %s vs %s"
,
string
(
b
),
data
)
}
}
pkg/cloudcfg/resource_printer_test.go
View file @
c3da356c
...
@@ -22,6 +22,7 @@ import (
...
@@ -22,6 +22,7 @@ import (
"reflect"
"reflect"
"testing"
"testing"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"gopkg.in/v1/yaml"
"gopkg.in/v1/yaml"
)
)
...
@@ -60,6 +61,43 @@ func TestYAMLPrinterPrint(t *testing.T) {
...
@@ -60,6 +61,43 @@ func TestYAMLPrinterPrint(t *testing.T) {
t
.
Fatal
(
err
)
t
.
Fatal
(
err
)
}
}
if
!
reflect
.
DeepEqual
(
testData
,
poutput
)
{
if
!
reflect
.
DeepEqual
(
testData
,
poutput
)
{
t
.
Error
(
"Test data and unmarshaled data are not equal"
)
t
.
Errorf
(
"Test data and unmarshaled data are not equal: %#v vs %#v"
,
poutput
,
testData
)
}
obj
:=
api
.
Pod
{
JSONBase
:
api
.
JSONBase
{
ID
:
"foo"
},
}
buf
.
Reset
()
printer
.
PrintObj
(
obj
,
buf
)
var
objOut
api
.
Pod
err
=
yaml
.
Unmarshal
([]
byte
(
buf
.
String
()),
&
objOut
)
if
err
!=
nil
{
t
.
Errorf
(
"Unexpeted error: %#v"
,
err
)
}
if
!
reflect
.
DeepEqual
(
obj
,
objOut
)
{
t
.
Errorf
(
"Unexpected inequality: %#v vs %#v"
,
obj
,
objOut
)
}
}
func
TestIdentityPrinter
(
t
*
testing
.
T
)
{
printer
:=
&
IdentityPrinter
{}
buff
:=
bytes
.
NewBuffer
([]
byte
{})
str
:=
"this is a test string"
printer
.
Print
([]
byte
(
str
),
buff
)
if
buff
.
String
()
!=
str
{
t
.
Errorf
(
"Bytes are not equal: %s vs %s"
,
str
,
buff
.
String
())
}
obj
:=
api
.
Pod
{
JSONBase
:
api
.
JSONBase
{
ID
:
"foo"
},
}
buff
.
Reset
()
printer
.
PrintObj
(
obj
,
buff
)
objOut
,
err
:=
api
.
Decode
([]
byte
(
buff
.
String
()))
if
err
!=
nil
{
t
.
Errorf
(
"Unexpeted error: %#v"
,
err
)
}
if
!
reflect
.
DeepEqual
(
&
obj
,
objOut
)
{
t
.
Errorf
(
"Unexpected inequality: %#v vs %#v"
,
obj
,
objOut
)
}
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment