Skip to content

Commit

Permalink
Add more tests, remove travis-ci integration
Browse files Browse the repository at this point in the history
  • Loading branch information
outdead committed Nov 14, 2020
1 parent 2bc277a commit ca7e697
Show file tree
Hide file tree
Showing 8 changed files with 227 additions and 54 deletions.
49 changes: 49 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: build

on:
push:
tags:
- v*
branches:
- master
- develop
pull_request:
branches: [ master ]

jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- name: Set up Go 1.x
uses: actions/setup-go@v2
with:
go-version: ^1.15

- name: Check out code into the Go module directory
uses: actions/checkout@v2

- name: Lint
uses: golangci/golangci-lint-action@v2
with:
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
version: v1.31

# Optional: working directory, useful for monorepos
# working-directory: somedir

# Optional: golangci-lint command line arguments.
# args: --issues-exit-code=0
args: --config=.golangci.yml

# Optional: show only new issues if it's a pull request. The default value is `false`.
only-new-issues: false

- name: Get dependencies
run: |
go get -v -t -d ./...
- name: Test
run: go test -v ./...

- name: Build
run: go build -v .
30 changes: 0 additions & 30 deletions .github/workflows/golangci-lint.yml

This file was deleted.

2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
.idea/
telnet_integration_test.go
.vscode/
vendor/
14 changes: 0 additions & 14 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
run:
skip-dirs:
- test/testdata_etc
- pkg/golinters/goanalysis/(checker|passes)
- data/
- .vscode/
- .directory/
- debug/
- vendor/
skip-files:
- Gopkg.lock
- .gitignore
- ".*_test.go$"

Expand Down Expand Up @@ -132,10 +125,3 @@ linters:
issues:
exclude:
- "`DefaultSettings` is a global variable" # (gochecknoglobals)

# golangci.com configuration
# https://github.com/golangci/golangci/wiki/Configuration
service:
golangci-lint-version: 1.31.x # use the fixed version to not introduce new linters unexpectedly
prepare:
- echo "here I can run custom commands, but no preparation needed for this repo"
4 changes: 0 additions & 4 deletions .travis.yml

This file was deleted.

13 changes: 12 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,19 @@ All notable changes to this project will be documented in this file.

## [Unreleased]

## [v1.0.1] - 2020-11-14
### Added
- Added the ability to run the help command on a real 7 Days to Die server. To do this, set environment variables
`TEST_7DTD_SERVER=true`, `TEST_7DTD_SERVER_ADDR` and `TEST_7DTD_SERVER_PASSWORD` with address and password from
7 Days to Die remote console.

### Changed
- Changed CI workflows and related badges. Integration with Travis-CI was changed to GitHub actions workflow. Golangci-lint
job was joined with tests workflow.

## v1.0.0 - 2020-10-06
### Added
- Initial implementation.

[Unreleased]: https://github.com/gorcon/telnet/compare/v1.0.0...HEAD
[Unreleased]: https://github.com/gorcon/telnet/compare/v1.0.1...HEAD
[v1.0.1]: https://github.com/gorcon/telnet/compare/v1.0.0...v1.0.1
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# telnet
[![golangci-lint](https://github.com/gorcon/telnet/workflows/golangci-lint/badge.svg)](https://github.com/gorcon/telnet/actions)
[![Go Report Card](https://goreportcard.com/badge/github.com/gorcon/telnet)](https://goreportcard.com/report/github.com/gorcon/telnet)
[![Build Status](https://travis-ci.org/gorcon/telnet.svg?branch=master)](https://travis-ci.org/gorcon/telnet)
# Telnet
[![GitHub Build](https://github.com/gorcon/telnet/workflows/build/badge.svg)](https://github.com/gorcon/telnet/actions)
[![Coverage](https://gocover.io/_badge/github.com/gorcon/telnet?0 "coverage")](https://gocover.io/github.com/gorcon/telnet)
[![Go Report Card](https://goreportcard.com/badge/github.com/gorcon/telnet)](https://goreportcard.com/report/github.com/gorcon/telnet)
[![GoDoc](https://img.shields.io/badge/godoc-reference-blue.svg)](https://godoc.org/github.com/gorcon/telnet)

7 Days to Die remote access to game [Command Console](https://7daystodie.gamepedia.com/Command_Console). This is not full [TELNET](https://en.wikipedia.org/wiki/Telnet) protocol implementation.
Expand Down
162 changes: 162 additions & 0 deletions telnet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ package telnet

import (
"bytes"
"encoding/json"
"fmt"
"os"
"strings"
"testing"
"time"

Expand Down Expand Up @@ -117,6 +120,156 @@ func TestConn_Execute(t *testing.T) {
assert.NoError(t, err)
assert.Equal(t, fmt.Sprintf("Please enter password:%s%s%s%s%s", CRLF, AuthSuccess, CRLF, MockCommandHelpResponse, CRLF), result)
})

if run := getVar("TEST_7DTD_SERVER", "false"); run == "true" {
addr := getVar("TEST_7DTD_SERVER_ADDR", "172.22.0.2:8081")
password := getVar("TEST_7DTD_SERVER_PASSWORD", "banana")

t.Run("7dtd server", func(t *testing.T) {
needle := `*** List of Commands ***
admin => Manage user permission levels
aiddebug => Toggles AIDirector debug output.
audio => Watch audio stats
automove => Player auto movement
ban => Manage ban entries
bents => Switches block entities on/off
BiomeParticles => Debug
buff => Applies a buff to the local player
buffplayer => Apply a buff to a player
chunkcache cc => shows all loaded chunks in cache
chunkobserver co => Place a chunk observer on a given position.
chunkreset cr => resets the specified chunks
commandpermission cp => Manage command permission levels
creativemenu cm => enables/disables the creativemenu
debuff => Removes a buff from the local player
debuffplayer => Remove a buff from a player
debugmenu dm => enables/disables the debugmenu ` + `
debugshot dbs => Lets you make a screenshot that will have some generic info
on it and a custom text you can enter. Also stores a list
of your current perk levels in a CSV file next to it.
debugweather => Dumps internal weather state to the console.
decomgr => ` + `
dms => Gives control over Dynamic Music functionality.
dof => Control DOF
enablescope es => toggle debug scope
exhausted => Makes the player exhausted.
exportcurrentconfigs => Exports the current game config XMLs
exportprefab => Exports a prefab from a world area
floatingorigin fo => ` + `
fov => Camera field of view
gamestage => usage: gamestage - displays the gamestage of the local player.
getgamepref gg => Gets game preferences
getgamestat ggs => Gets game stats
getoptions => Gets game options
gettime gt => Get the current game time
gfx => Graphics commands
givequest => usage: givequest questname
giveself => usage: giveself itemName [qualityLevel=6] [count=1] [putInInventory=false] [spawnWithMods=true]
giveselfxp => usage: giveselfxp 10000
help => Help on console and specific commands
kick => Kicks user with optional reason. "kick playername reason"
kickall => Kicks all users with optional reason. "kickall reason"
kill => Kill a given entity
killall => Kill all entities
lgo listgameobjects => List all active game objects
lights => Debug views to optimize lights
listents le => lists all entities
listplayerids lpi => Lists all players with their IDs for ingame commands
listplayers lp => lists all players
listthreads lt => lists all threads
loggamestate lgs => Log the current state of the game
loglevel => Telnet/Web only: Select which types of log messages are shown
mem => Prints memory information and unloads resources or changes garbage collector
memcl => Prints memory information on client and calls garbage collector
occlusion => Control OcclusionManager
pirs => tbd
pois => Switches distant POIs on/off
pplist => Lists all PersistentPlayer data
prefab => ` + `
prefabupdater => ` + `
profilenetwork => Writes network profiling information
profiling => Enable Unity profiling for 300 frames
removequest => usage: removequest questname
repairchunkdensity rcd => check and optionally fix densities of a chunk
saveworld sa => Saves the world manually.
say => Sends a message to all connected clients
ScreenEffect => Sets a screen effect
setgamepref sg => sets a game pref
setgamestat sgs => sets a game stat
settargetfps => Set the target FPS the game should run at (upper limit)
settempunit stu => Set the current temperature units.
settime st => Set the current game time
show => Shows custom layers of rendering.
showalbedo albedo => enables/disables display of albedo in gBuffer
showchunkdata sc => shows some date of the current chunk
showClouds => Artist command to show one layer of clouds.
showhits => Show hit entity locations
shownexthordetime => Displays the wandering horde time
shownormals norms => enables/disables display of normal maps in gBuffer
showspecular spec => enables/disables display of specular values in gBuffer
showswings => Show melee swing arc rays
shutdown => shuts down the game
sleeper => Show sleeper info
smoothworldall swa => Applies some batched smoothing commands.
sounddebug => Toggles SoundManager debug output.
spawnairdrop => Spawns an air drop
spawnentity se => spawns an entity
spawnentityat sea => Spawns an entity at a give position
spawnscouts => Spawns zombie scouts
SpawnScreen => Display SpawnScreen
spawnsupplycrate => Spawns a supply crate where the player is
spawnwanderinghorde spawnwh => Spawns a wandering horde of zombies
spectator spectatormode sm => enables/disables spectator mode
spectrum => Force a particular lighting spectrum.
stab => stability
starve hungry food => Makes the player starve (optionally specify the amount of food you want to have in percent).
switchview sv => Switch between fpv and tpv
SystemInfo => List SystemInfo
teleport tp => Teleport the local player
teleportplayer tele => Teleport a given player
thirsty water => Makes the player thirsty (optionally specify the amount of water you want to have in percent).
traderarea => ...
trees => Switches trees on/off
updatelighton => Commands for UpdateLightOnAllMaterials and UpdateLightOnPlayers
version => Get the currently running version of the game and loaded mods
visitmap => Visit an given area of the map. Optionally run the density check on each visited chunk.
water => Control water settings
weather => Control weather settings
weathersurvival => Enables/disables weather survival
whitelist => Manage whitelist entries
wsmats workstationmaterials => Set material counts on workstations.
xui => Execute XUi operations
xuireload => Access xui related functions such as reinitializing a window group, opening a window group
zip => Control zipline settings`

needle = strings.Replace(needle, "\n", "\r\n", -1)
needle = strings.Replace(needle, "some generic info\r\n", "some generic info\n", -1)
needle = strings.Replace(needle, "Also stores a list\r\n", "Also stores a list\n", -1)

conn, err := Dial(addr, password)
if err != nil {
t.Fatal(err)
}
defer func() {
assert.NoError(t, conn.Close())
}()

result, err := conn.Execute("help")
assert.NoError(t, err)

if !strings.Contains(result, needle) {
diff := struct {
R string
N string
}{R: result, N: needle}

js, _ := json.Marshal(diff)
fmt.Println(string(js))

t.Error("response is not contain needle string")
}
})
}
}

func TestConn_Interactive(t *testing.T) {
Expand Down Expand Up @@ -164,3 +317,12 @@ func TestConn_Interactive(t *testing.T) {
assert.Equal(t, fmt.Sprintf("Please enter password:%s%s%s%s%s", CRLF, AuthSuccess, CRLF, MockCommandHelpResponse, CRLF), w.String())
})
}

// getVar returns environment variable or default value.
func getVar(key string, fallback string) string {
if value := os.Getenv(key); value != "" {
return value
}

return fallback
}

0 comments on commit ca7e697

Please sign in to comment.